var xmlhttp;
function loadXMLDoc(url) {
    xmlhttp = null;
    if (window.XMLHttpRequest) {// code for IE7, Firefox, Opera, etc.
        xmlhttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (xmlhttp != null) {
        xmlhttp.onreadystatechange = state_Change;
        xmlhttp.open("GET", url, true);
        xmlhttp.send(null);
    }
    else {
        alert("Your browser does not support XMLHTTP.");
    }
}

function state_Change() {
    if (xmlhttp.readyState == 4) {// 4 = "loaded"
        if (xmlhttp.status == 200) {// 200 = "OK"
            var reeditHtml = xmlhttp.responseText;
            var t = reeditHtml.indexOf("reeditBtn");
            if (t > 0) {
                t = reeditHtml.indexOf('div', t);
                reeditHtml = reeditHtml.substring(t + 4)
            }
            t = reeditHtml.indexOf('tableStyle');
            if (t > 0) {
                reeditHtml = reeditHtml.substring(0, reeditHtml.lastIndexOf('style', t) - 1) + reeditHtml.substring(reeditHtml.indexOf('style', t) + 6);
            }
            myEditor.setValue(reeditHtml);
        }
        else {
            alert("Problem retrieving XML data:" + xmlhttp.statusText);
        }
    }
}
function resetTiltle() {
    var str = window.location.search.substring(1);
    str = decodeURI(str);
    var t1 = str.indexOf("jikepages");
    t1 = str.indexOf('/', t1);
    str = str.substring(t1 + 1);
    var qs = str.split('/');
    if (qs.length == 3) {
        var t2 = qs[2].indexOf('_');
        var userName = qs[2].substring(0, t2);
        window.currentPageOwner=userName;
        var pageTitle = qs[2].substring(t2 + 1).split('.')[0];
        document.getElementById('pageTitle').value = pageTitle;
        document.getElementById('pageTitleType1').value=qs[0];
        document.getElementById('pageTitleType2').value=qs[1];
    }
}

function loadReEdit() {
    if (window.location.search.length > 1) {
        loadXMLDoc(window.location.search.substring(1));
        resetTiltle();
    }
}
loadReEdit();
